<?php
require_once ('conn.php');
require_once ('top.php');
if($_SESSION['role']==1){
      Header("Location:index.php"); 
    }elseif($_SESSION['role']==3){
           Header("Location:dotlistMaster.php"); 
   }



    
    $i=0;//网点数量
    $goodsnum=0;//商品数量
    $result=mysql_query("select * from ci_contact where disable=0 and isDelete=0 and bhstaffid=".$_SESSION['userid']); 
    while($row=mysql_fetch_array($result)) 
    {
        $num = mysql_fetch_row(mysql_query("select count(*) from ci_wdgoods where contactNumber='".$row['number']."'"));
        $goodsnum =  $goodsnum+$num[0];
        $i++;
    }

    $result2=mysql_query("SELECT * FROM ci_invoice WHERE bhstaffid = $_SESSION[userid] and isDelete=0 AND hxStateCode = 2"); 
    $j=0;//完成补货单数量
    $goodsnum2 =0;//完成补货商品数量
    $goodsclass2 =0;///完成补货商品种类
    while($row2=mysql_fetch_array($result2)) 
    {
        $num = mysql_fetch_row(mysql_query("select sum(qty) from ci_invoice_info where billNo='".$row2['billNo']."'"));
        $num2 = mysql_fetch_row(mysql_query("select COUNT(*) from (SELECT invId FROM ci_invoice_info as t1 INNER JOIN ci_invoice as t2 where t1.isDelete=0 and t2.bhstaffid=$_SESSION[userid] and t2.hxStateCode=2 and t1.buId = $row2[buId] GROUP BY invId) as t3 "));
        $goodsnum2 =  $goodsnum2+$num[0];
        $goodsclass2 = $goodsclass2 + $num2[0];
        $j++;
    }
    
    $result3=mysql_query("SELECT * FROM ci_invoice WHERE bhstaffid = $_SESSION[userid] and isDelete=0 AND hxStateCode = 1"); 
    $k=0;//完成补货单数量
    $goodsnum3 =0;//完成补货商品数量
    $goodsclass3 =0;///完成补货商品种类
    while($row3=mysql_fetch_array($result3)) 
    {
       
        $num = mysql_fetch_row(mysql_query("select sum(qty) from ci_invoice_info where billNo='".$row3['billNo']."'"));
        $goodsnum3 =  $goodsnum3+$num[0];
        $num3 = mysql_fetch_row(mysql_query("select COUNT(*) from (SELECT invId FROM ci_invoice_info as t1 INNER JOIN ci_invoice as t2 where t1.isDelete=0 and t2.bhstaffid=$_SESSION[userid] and t2.hxStateCode=1 and t1.buId = $row3[buId] GROUP BY invId) as t3 "));
        $goodsclass3 = $goodsclass3 + $num3[0];
        $k++;
    }
    
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>优易购</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <script src="js/jquery-1.11.0.min.js"></script>
</head>
<script>
function showTime(){
    nowtime=new Date();
    year=nowtime.getFullYear();
    month=nowtime.getMonth()+1;
    date=nowtime.getDate();
    document.getElementById("mytime").innerText=year+"年"+month+"月"+date;
}    
    setInterval("showTime()");
</script>
<body>
    <div class="top">
        
        <span>补货人员 - 首页</span>
        <div class="tright"><span class="outlogin">退出登陆</span></div>
    </div>
    <div class="bodybut">
        <div class="rili">
            <img src="img/rl.png" alt="">
            <span id="mytime"></span>
        </div>
        <div class="supply_index" style="background: #1D9BE5;">
                <div class="supply_33">
                    <p class="sj33p1"><?=$i?></p>
                    <p class="sj33p2">网点数量</p>
                </div>
                <div class="supply_33">
                    <p class="sj33p1"></p>
                    <p class="sj33p2"></p>
                </div>
                <div class="supply_33">
                    <p class="sj33p3"><?=$goodsnum?></p>
                    <p class="sj33p2">商品种类</p>
                </div>
            </div>
            <p class="pdyesno"><img src="img/status1.png" alt="">已完成</p>
            <div class="supply_index" style="background: #70B439;">
                <div class="supply_33">
                    <p class="sj33p1"><?=$j?></p>
                    <p class="sj33p2">补货单数量</p>
                </div>
                <div class="supply_33">
                    <p class="sj33p1"><?=$goodsclass2?></p>
                    <p class="sj33p2">商品种类</p>
                </div>
                <div class="supply_33">
                    <p class="sj33p3"><?=$goodsnum2*-1?></p>
                    <p class="sj33p2">补货商品数量</p>
                </div>
            </div>
            <p class="pdyesno"><img src="img/status2.png" alt="">未完成</p>
            <div class="supply_index" style="background: #FF0000;">
                <div class="supply_33">
                    <p class="sj33p1"><?=$k?></p>
                    <p class="sj33p2">补货单数量</p>
                </div>
                <div class="supply_33">
                    <p class="sj33p1"><?=$goodsclass3?></p>
                    <p class="sj33p2">商品种类</p>
                </div>
                <div class="supply_33">
                    <p class="sj33p3"><?=$goodsnum3*-1?></p>
                    <p class="sj33p2">补货商品数量</p>
                </div>
            </div>
    </div>
    <div style=" width:100%;height:100px; float:left;"></div>
    <div class="foot">
       
        <div class="footon">
        <img src="img/f1.png" alt="">
        <p>首页</p>
        </div>
        
        <a href="supply_pandian.php">
        <div>
        <img src="img/f22.png" alt="">
        <p>网点</p>
        </div>
        </a>
        
        <a href="supply.php">
        <div>
        <img src="img/f33.png" alt="">
        <p>补货</p>
        </div>
        </a>
    </div>
</body>
<script src="js/outlogin.js"></script>
</html>